package com.grts.mall.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.grts.mall.common.CommonResult;
import com.grts.mall.pojo.User;
import com.grts.mall.service.UserService;

@RestController
public class LoginController {

	@Autowired
	private UserService userService;
	
	@RequestMapping("/login")
	public CommonResult login(@RequestBody User user ,HttpSession session) {
		
		CommonResult res = this.userService.login(user);
		if (res.getCode()==0) {
			session.setAttribute("newuser", res.getData());
		}
		
		return res;
	}
}
